#include "BindingCube.h"

namespace collisions
{
	BindingCube::BindingCube(const Vector3D pos, float _width, float _height, float _depth)
	{
		width  = _width;
		height = _height;
		depth  = _depth;
		left   = pos.X - width / 2;
		right  = pos.X + width / 2;
		top    = pos.Y - height / 2;
		bottom = pos.Y + height / 2;
		front  = pos.Z - depth / 2;
		back   = pos.Z + depth / 2;
	}

	BindingCube::BindingCube(float _left, float _right, float _top, float _bottom, float _front, float _back)
	{
		left   = _left;
		right  = _right;
		top    = _top;
		bottom = _bottom;
		front  = _front;
		back   = _back;
		width  = right - left;
		height = bottom - top;
		depth  = back - front;
	}

	bool BindingCube::collidesWith(const BindingCube o)
	{
		return left < o.right 
			&& right > o.left
			&& top < o.bottom
			&& bottom > o.top
			&& front < o.back
			&& back > o.front;
	}

	void BindingCube::moveTo(Vector3D newPosition)
	{
		left   = newPosition.X - width / 2;
		right  = newPosition.X + width / 2;
		top    = newPosition.Y - height / 2;
		bottom = newPosition.Y + height / 2;
		front  = newPosition.Z - depth / 2;
		back   = newPosition.Z + depth / 2;
	}

	void BindingCube::moveBy(Vector3D translation)
	{
		left   += translation.X;
		right  += translation.X;
		top    += translation.Y;
		bottom += translation.Y;
		front  += translation.Z;
		back   += translation.Z;
	}
}